package com.acme.exchange.network.client;

import com.acme.exchange.network.proto.Protocol.ExchangeMessage;
import com.acme.exchange.network.proto.Protocol.ExchangeMessage.MessageType;
import com.acme.exchange.network.proto.Protocol.ExchangeMessage.OrderStatus;
import com.acme.exchange.network.proto.Protocol.ExchangeMessage.OrderType;

public class ServerResponseProcessor {

	public static void process(ExchangeMessage message) {
		
//		System.out.println(message);
		
		if (message.getMessageType() == MessageType.REJECT) {
			System.out.println(message.getComment());
			return;
		}
		if (message.getMessageType() == MessageType.EXECUTION_REPORT) {
			if (message.getOrderStatus() == OrderStatus.REJECTED) {
				System.out.println("order #" + message.getClientOrderId()
						+ "has been rejected because " + message.getComment());
				return;
			}
			if (message.getOrderStatus() == OrderStatus.NEW) {
				if (message.getOrderType() == OrderType.LIMIT) {					
					System.out.println("new order #"
							+ message.getClientOrderId() + ", ("
							+ message.getOrderId() + ") "
							+ message.getSymbol() + ", "
							+ message.getSide() + ", " + message.getOrderType() 
							+ ", <" + message.getQuantity() + ">, "
							+ message.getPrice()
							+ ".");
					return;
				} else {
					System.out.println("new order #"
							+ message.getClientOrderId() + ", ("
							+ message.getOrderId() + ") "
							+ message.getOrderType() + ", " + message.getSide()
							+ ", " + message.getQuantity() + ", "
							+ message.getSymbol() + ".");
					return;
				}

			} else { // OrderStatus = FILLED/PART_FILLED
				System.out.println("order #" + message.getClientOrderId()
						+ ", (" + message.getOrderId() + ") "
						+ message.getOrderStatus() + ", "
						+ message.getCumulativeQuantity() 
						+ ", " + message.getLastPrice() + ", counterparty " + 
						message.getCounterparty() + ".");
				return;
			}
		}
	}

}
